import socket
# 创建socket
client = socket.socket()
# 连接到服务端
client.connect(("localhost", 6666))
print("与服务器建立连接成功")
# 发送信息
while True:
    msg = input("输入发送消息：")
    if msg == "exit":
        break
    client.send(msg.encode("utf-8"))
    # 接收消息 阻塞的
    data = client.recv(1024).decode("utf-8")
    print(f"服务端回复的消息是{data}")
# 关闭连接
client.close()